
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Dialogs {
  static Future<T> runWithDialogsWhenErrorOccurres<T>(BuildContext context, Future<T> action(), {void onError(), void onCompleted()}) async {
    try {
      var result = await action();
      onCompleted?.call();
      return result;
    }
    catch (error) {
      onError?.call();
      return await showDialog(context: context, barrierDismissible: false, child: CupertinoAlertDialog(
        title: Text("بىر مەسىلىگە يولۇقتۇق"),
        actions: <Widget>[
          CupertinoButton(
            onPressed: (){
              Navigator.of(context).pop();
            },
            child: Text("چۈشىنەرلىك"),
          )
        ],
        content: Text(error.toString()),
      ));
    }
  }
}
